package cn.suimg.neo4j.config;

import cn.suimg.neo4j.graph.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * 公用常量类
 * @author Suimg
 */
public interface Constant {

    /**
     * 酷狗音乐配置 -> 客户端ID
     */
    String KUGOU_CONFIG_APP_ID = "1155";

    /**
     * 酷狗音乐配置 -> 用户ID
     */
    String KUGOU_CONFIG_USER_ID = "578767489";

    /**
     * 酷狗音乐配置 -> MID
     */
    String KUGOU_CONFIG_MID = "0a1f010f0ad67e269a4eb67b269f5067";

    /**
     * 酷狗音乐登录地址
     */
    String KUGOU_LOGIN_URL = "https://login-user.kugou.com/v1/login/";

    /**
     * 百度API获取令牌接口地址
     */
    String BAIDU_API_GET_ACCESS_TOKEN_URL = "http://openapi.baidu.com/oauth/2.0/token";

    /**
     * 百度API文本转语音接口地址
     */
    String BAIDU_API_TEXT_2_VOICE_API_URL = "http://tsn.baidu.com/text2audio";

    /**
     * 百度API语音识别接口地址
     */
    String BAIDU_API_VOICE_2_TEXT_API_URL = "http://vop.baidu.com/server_api";

    /**
     * 百度API图片文本识别接口地址
     */
    String BAIDU_API_IMAGE_2_TEXT_API_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=%s";

    /**
     * 百度API验证文本非法接口
     */
    String BAIDU_API_VERIFY_TEXT_LEGAL_API_URL = "https://aip.baidubce.com/rest/2.0/antispam/v2/spam?access_token=%s";

    /**
     * 搜索歌曲接口地址
     */
    String KUGOU_SEARCH_SONG_URL = "http://songsearch.kugou.com/song_search_v2?keyword=%s&page=%d&pagesize=%d";

    /**
     * 搜索歌词接口地址
     */
    String KUGOU_SEARCH_LYRIC_URL = "http://lyrics.kugou.com/search?client=pc&duration=%d000&hash=%s&keyword=%s&man=no&ver=1";

    /**
     * 下载歌词接口地址
     */
    String KUGOU_DOWNLOAD_LYRIC_URL = "http://lyrics.kugou.com/download?ver=1&client=pc&fmt=lrc&charset=utf8&accesskey=%s&id=%d";

    /**
     * 搜索歌手写真接口地址
     */
    String KUGOU_SEARCH_SINGER_IMAGE_URL = "http://kmr.service.kugou.com/v1/author_image/audio";

    /**
     * 查询歌手信息接口地址
     */
    String KUGOU_QUERY_SINGER_INFO_URL = "http://ioscdn.kugou.com/api/v3/singer/info?singerid=%d";

    /**
     * 下载歌曲接口地址
     */
    String KUGOU_DOWNLOAD_MUSIC_URL = "http://trackercdn.kugou.com/i/v2/";

    /**
     * 搜索歌手信息
     */
    String KUGOU_SEARCH_SINGER_ID_URL = "http://so.service.kugou.com/get/complex?callback=&word=%s";

    /**
     * 查看专辑信息接口
     */
    String KUGOU_QUERY_ALBUM_INFO_URL = "http://ioscdn.kugou.com/api/v3/album/info?albumid=%d";

    /**
     * 查询专辑内歌曲名称列表接口
     */
    String KUGOU_QUERY_ALBUM_INCLUDES_URL = "http://mac.kugou.com/v2/musicol/yueku/v1/album/single/%d-92.html";

    /**
     * 查询歌手发布了哪些专辑列表接口
     */
    String KUGOU_QUERY_SINGER_ALBUM_LIST_URL = "http://ioscdn.kugou.com/api/v3/singer/album?page=1&pagesize=400&singerid=%d";

    /**
     * 查询酷狗分享码接口地址
     */
    String KUGOU_QUERY_SHARE_URL_INFO_URL = "https://m3ws.kugou.com/zlist/list";

    /**
     * 查询歌曲演唱者列表接口地址
     */
    String KUGOU_QUERY_SONG_SINGER_LIST_URL = "http://kmr.service.kugou.com/v2/album_audio/audio";

    /**
     * 查詢https的播放地址
     */
    String KUGOU_QUERY_SONG_PLAY_URL_WITH_SSL = "https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback=&hash=%s&mid=" + KUGOU_CONFIG_MID;


    String KUGOU_QUERY_MV_PLAY_URL = "https://trackermv.kugou.com/interface/index?cmd=100&hash=%s&key=%s&ext=mkv";


    /**
     * 查询搜索记录数 条件(歌手,专辑,歌曲)
     */
    String CQL_COUNT_WITH_SINGER_ALBUM_SONG = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and albumGraph.name=~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct count(%s) as counts";

    /**
     * 搜索条件(歌手,专辑,歌曲)
     */
    String CQL_QUERY_WITH_SINGER_ALBUM_SONG = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and albumGraph.name=~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct %s skip %d limit %d";

    /**
     * 查询搜索记录数 条件(歌手,专辑)
     */
    String CQL_COUNT_WITH_SINGER_ALBUM = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and albumGraph.name=~ '.*%s.*' return distinct count(%s) as counts";

    /**
     * 搜索条件(歌手,专辑)
     */
    String CQL_QUERY_WITH_SINGER_ALBUM = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and albumGraph.name=~ '.*%s.*' return distinct %s skip %d limit %d";

    /**
     * 查询搜索记录数 条件(歌手,歌曲)
     */
    String CQL_COUNT_WITH_SINGER_SONG = " match (singerGraph:歌手) - [:演唱] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct count(%s) as counts";

    /**
     * 搜索条件(歌手,歌曲)
     */
    String CQL_QUERY_WITH_SINGER_SONG = " match (singerGraph:歌手) - [:演唱] -> (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct %s skip %d limit %d";

    /**
     * 查询搜索记录数 条件(歌手,专辑,歌曲)
     */
    String CQL_COUNT_WITH_ALBUM_SONG = " match (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where albumGraph.name=~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct count(%s) as counts";

    /**
     * 搜索条件(歌手,专辑,歌曲)
     */
    String CQL_QUERY_WITH_ALBUM_SONG = " match (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where albumGraph.name=~ '.*%s.*' and songGraph.name =~ '.*%s.*' return distinct %s skip %d limit %d";

    /**
     * 查询搜索记录数 条件(歌手)返回 专辑
     */
    String CQL_COUNT_WITH_SINGER_RETURN_ALBUM = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑)  where singerGraph.name =~ '.*%s.*' return distinct count(albumGraph) as counts";

    /**
     * 搜索条件(歌手)返回 专辑
     */
    String CQL_QUERY_WITH_SINGER_RETURN_ALBUM = " match (singerGraph:歌手) - [:发布] -> (albumGraph:专辑) where singerGraph.name =~ '.*%s.*' return distinct albumGraph skip %d limit %d";

    /**
     * 查询搜索记录数 条件(歌手)返回 歌曲
     */
    String CQL_COUNT_WITH_SINGER_RETURN_SONG = " match (singerGraph:歌手) - [:演唱] -> (songGraph:歌曲)  where singerGraph.name =~ '.*%s.*' return distinct count(songGraph) as counts";

    /**
     * 搜索条件(歌手)返回 歌曲
     */
    String CQL_QUERY_WITH_SINGER_RETURN_SONG = " match (singerGraph:歌手) - [:演唱] ->  (songGraph:歌曲) where singerGraph.name =~ '.*%s.*' return distinct songGraph skip %d limit %d";

    /**
     * 查询搜索记录数 条件(专辑) 返回 歌曲
     */
    String CQL_COUNT_WITH_ALBUM_RETURN_SONG = " match (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where albumGraph.name=~ '.*%s.*' return distinct count(songGraph) as counts";

    /**
     * 搜索条件(专辑) 返回 歌曲
     */
    String CQL_QUERY_WITH_ALBUM_RETURN_SONG = " match (albumGraph:专辑) - [:包含] -> (songGraph:歌曲) where albumGraph.name=~ '.*%s.*' return distinct songGraph skip %d limit %d";

    /**
     *  查询搜索记录数 条件(歌曲)
     */
    String CQL_COUNT_WITH_SONG = "match (songGraph:歌曲) where songGraph.name=~ '.*%s.*' return distinct count(songGraph) as counts";

    /**
     * 搜索歌曲 条件(歌曲)
     */
    String CQL_QUERY_WITH_SONG = "match (songGraph:歌曲) where songGraph.name=~ '.*%s.*' return distinct songGraph skip %d limit %d";

    /**
     * 空的分页结果
     */
    Page<?> EMPTY_PAGE_RESULT = new PageImpl<>(new ArrayList<>(), Pageable.unpaged(),0L);

    /**
     * 动态查询类列表
     */
    Map<String,Class<? extends NeoGraph>> DYNAMIC_QUERY_CLASS_MAPPING = new HashMap<>();


    Map<String,String> LABEL_2_GRAPH_MAPPING = new HashMap<>();

    /**
     * Neo4j 操作符映射
     */
    Map<String,String> CQL_OPERATE_MAPPING = new HashMap<String, String>(){{
        put("eq","=");
        put("ne","<>");
        put("gt",">");
        put("lt","<");
        put("ge",">=");
        put("le","<=");
        put("lk","=~");
    }};

    /**
     * 普通CQL查询模板
     */
    String CQL_QUERY_TEMPLATE = "match (%s:%s) - [%s:%s] - (%s:%s) where %s return distinct * skip %d limit %d";

    /**
     * 任意查询CQL查询模板
     */
    String CQL_QUERY_ANYTHING_TEMPLATE = "match r = (%s:%s) - [] - () where %s return distinct r skip %d limit %d";

    /**
     * 普通CQL计数查询模板
     */
    String CQL_COUNT_TEMPLATE = "match (%s:%s) - [%s:%s] - (%s:%s) where %s return count(1) as counts";

    /**
     * 任意查询CQL计数查询模板
     */
    String CQL_COUNT_ANYTHING_TEMPLATE = "match r = (%s:%s) - [] - () where %s return count(r) as counts";


    Function<Class<?>,String> getClassName = clazz -> {
        String classname = clazz.getName();
        return classname.substring(classname.lastIndexOf(".") + 1);
    };


    String TEMP_DIR = System.getProperty("java.io.tmpdir");
}
